<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" title="码上证明"
		:isBack="true" backText="返回"></cu-custom>
		<view>
			<zh-text :value="proveData.aac002" type="text" label="身份证"
			labelAlign="left" inputAlign="right" ></zh-text>
			<zh-text :value="proveData.proveName" type="text" label="证书/职业名称"
			labelAlign="left" inputAlign="right" ></zh-text>
			<view class="cu-form-group">
				<input type="text"  maxlength="8" name="" v-model="imgCode" placeholder="请输入图片验证码"/>
				<image :src="imgSrc" @click="initCode" mode="" class="img-captcha"></image>
			</view>
			<view class="flex flex-direction" style="padding-top: 10rpx;">
				<button class="cu-btn shadow margin-tb-sm lg bg-gradual-blue-light" @tap="checkImgCode">查<text style="width: 50rpx;"></text>看</button>
			</view>
		</view>
	</view>
</template>

<script>
	import util from '@/common/util/util.js';
	import reqConfig from '@/common/config/reqConfig.js';
	import api from '@/api/society/home/home.js'; 
	export default {
		data(){
			return {
				proveData:{},
				pageId:'',
				imgSrc:'',
				imgCode:'',
				fileUrl:''
			}
		},
		onLoad: function (option) {
			this.pageId=util.uuid();
			this.proveData = this.$Route.query.proveData;
			this.initCode();
		},
		methods: {
			initCode() {
				const url = reqConfig.baseUrl+"/app/api/person/getImgCode?pageId="+this.pageId+"&time="+new Date().getTime();
				console.log(url);
				this.imgSrc=url
			},
			printProve(){
				this.$http.post(api.printProve,this.proveData).then(res => {
					if(res.code==0){
						// this.$http.get(res.result);
						let params = {};
						params.title = this.proveData.proveName;
						params.contentType = "file";
						params.fileUrl = res.result;
						params.fileType = "pdf";
						this.$Router.push({name: "articleFile", params: params})
					}
				}).catch(error => {
				})
			},
			checkImgCode(){
				const url = reqConfig.baseUrl+"/app/api/person/check/imgCode?pageId="+this.pageId+
				"&imgCode="+this.imgCode;
				this.$http.get(url).then(res => {
					this.printProve();
				}).catch(error => {
				})
				
			}
		}
	}
</script>

<style>
	.img-captcha{
		width: 200rpx;
		line-height: 70rpx;
		height: 70rpx;
		text-align: center;
		margin: 0;
	}
</style>
